package XMLread;
import java.util.ArrayList;
import java.util.StringTokenizer;

import sp.whereru.Loc;

import com.google.android.maps.GeoPoint;

public class Space {

	private int buildingid;
	private int floor;
	private GeoPoint[] shape;
	private Loc[] points;
	private String room;
	private String room_label;


	public Space(String shapePoints, String buildingid, String flr, String room, String room_label){
		setShape(shapePoints);
		setBuildingID(buildingid);
		setFloor(flr);
		setRoom(room);
		setRoomLabel(room_label);
		
	}

	public void setBuildingID(String id){
		buildingid = Integer.valueOf(id);
	}

	public Integer getBuildingID(){
		return buildingid;
	}

	public void setFloor(String flr){
		floor = Integer.valueOf(flr);
	}

	public int getFloor(){
		return floor;
	}

	public void setRoom(String room){
		this.room = room;
	}

	public String getRoom(){
		return room;
	}

	public void setRoomLabel(String roomLabel){
		room_label = roomLabel;
	}

	public String getRoomLabel(){
		return room_label;
	}

	//lat, lon
	public void setShape(String shapePoints){
		StringTokenizer st = new StringTokenizer(shapePoints, "|");
		shape = new GeoPoint[st.countTokens()];
		points = new Loc[st.countTokens()];
		int i = 0;
		
		//process each edge
		while(st.hasMoreTokens()){
			
			//split edge into lat and long
			StringTokenizer edge = new StringTokenizer(st.nextToken(), " ");
			double lon = Double.valueOf(edge.nextToken());
			double lat = Double.valueOf(edge.nextToken());
			shape[i] = new GeoPoint((int) (lat * 1e6), (int) (lon * 1e6));
			points[i] = new Loc(lat,lon);
			i++;
		}
	}

	public GeoPoint[] getShape(){
		return shape;
	}
	
	public ArrayList<GeoPoint> getArrayList(){
		ArrayList<GeoPoint> points = new ArrayList<GeoPoint>();
		int i = 0;
		while(i < shape.length) {
			points.add(shape[i]);
			i++;
		}
		return points;
	}
	
	public Loc[] getPoints(){
		return points;
	}
}
